<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试$.post()</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
   $(function () {
       $("#btnId").click(function () {
       $.ajaxSetup({
          async:false
       });
  $.get(
    "${pageContext.request.contextPath}/TestAjaxServlet",
           {username:$("[name='username']").val(),password:$("[name='password']")},
      function (obj) {
          alert(obj);
      },
      "text"

  );
           $.post(
               "${pageContext.request.contextPath}/TestAjaxServlet",
               {username:$("[name='username']"),password:$("[name='password']")},
               function (obj) {
                   alert(obj)
               },
               "text"
           );

           $.ajax({
               url:"",
               type:"POST",
               deta:"",
               detaType:"text",
               success:function (obj) {
                   alert(obj)
               }

           });
       });
   });
    </script>
</head>
<body>
用户名：<input type="text" name="username">
密码：<input type="password" name="password">
<input type="button" value="登录" id="btnId">
</body>
</html>
